package day1106_1;

import java.io.*;

class  Cat  implements  Serializable{String name;}
public class F2 {//ObjectOutputStream也不能单独使用(封装一个字节流)

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //1.创建ObjectOutputStream  oos
        ObjectOutputStream  oos=
                new ObjectOutputStream(   new FileOutputStream("D:\\obj1106.txt")  );
        Cat   tom=new Cat();  tom.name="汤姆";
        oos.writeObject(tom);//2. oos.writeObject()
        oos.close();//3.oos.close()

        ObjectInputStream  ois=
                new ObjectInputStream( new FileInputStream("D:\\obj1106.txt"));
        //1.
        Cat  c=(Cat)ois.readObject();//2.
        System.out.println(c.name);
        ois.close();//3.
    }

}





